home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14315 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: linux.nildram.co.uk!usenet
  2. From: colin@greench.co.uk (Colin Wray)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: when to inherit, when to compose...
  5. Date: Fri, 29 Mar 1996 21:57:33 GMT
  6. Organization: Greenchurch Software Ltd
  7. Message-ID: <4jhmmq$smd@linux.nildram.co.uk>
  8. References: <4j943p$7es@ulowell.uml.edu>
  9. NNTP-Posting-Host: pppn.nildram.co.uk
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. jlee@jupiter.cs.uml.edu (John Peter Lee) wrote:
  13.  
  14. >Hi:
  15.  
  16. >  I'm wondering about an OO design. Under what circumstances is it more
  17. >  advantageous to use an inheritance hierarchy for a design, as opposed
  18. >  to using object containment, and vice versa?
  19.  
  20. >  With object containment: class "A" has a member class "B" declared
  21. >  within it. A acts as a kindof handle class (I think) that forwards
  22. >  requests to B, and handles B's output. 
  23.  
  24. >  With inheritance: class "A" is a base class, and class "B" is a derived
  25. >  class. Then A has virtual functions that are implemented in B. 
  26.  
  27. >  -> Are there any general rules of thumb to apply here? Any literature?
  28.  
  29. Composition: "A" has a "B".
  30. Inheritance:  "A" is a kind of "B"
  31. "Car" is a kind of "Vehicle" that has a "Engine".
  32.  
  33. >  
  34. >  The design I am currently developing involves classes that are graphical
  35. >  in nature - they have a lot of Motif and graphics-related info. I want to
  36. >  shield all of this graphics stuff from certain objects that interact with
  37. >  these classes in a non-graphical way (I'm placing graphics descriptors
  38. >  into a type of history structure, and doing a lot of manipulations of
  39. >  these descriptors - actual graphics isn't required for any of this stuff).
  40. >  I'm wondering whether or not to shield things via containment by having
  41. >  a graphical class ptr as a member of the base class, or via inheritance by
  42. >  having a subclass inherit the graphical stuff from a graphical base class.
  43.  
  44. The objects should already encapsulate their data structures, making
  45. them accessable only via their API. If the graphical functions are
  46. protected, they would only be accessable by 'friend' class functions.
  47.  
  48. >thanks in advance - please reply directly to me.
  49.  
  50. >jp
  51.  
  52. >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  53. >JP Lee               Institute for Visualization and Perception Research
  54. >jlee@cs.uml.edu                    University of Massachusetts at Lowell
  55. >(508) 934-3384                  1 University Ave. Lowell, MA 01854
  56. >(508) 452-4298 fax
  57.  
  58. >              Don't accept cheap imitations !!!!
  59.  
  60. >    Support H.R. 1500 - America's Redrock Wilderness Act !
  61.  
  62. >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  63.  
  64.  
  65. ----------------------------------------------------------------------------
  66. Colin Wray, Greenchurch Software Ltd, UK
  67. Email: colin@greench.co.uk
  68. ----------------------------------------------------------------------------
  69.  
  70.